﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace team33_ass3
{
    class MapBlock : IEquatable<MapBlock>
    {
        private bool solid;
        private int x;
        private int y;
        private int width;

        /// <summary>
        /// This constructor should only be used for creating temporary MapBlocks,
        /// and is not used for production.
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        public MapBlock(int x, int y)
        {

        }

        public MapBlock(int x, int y, int width, bool solid)
        {
            this.solid = solid;
            this.x = x;
            this.y = y;
            this.width = width;
        }

        public bool canWalkTo(MapBlock block)
        {
            if ((Math.Abs(x - block.getX()) == 1 && (y - block.getY()) == 0 || Math.Abs(y - block.getY()) == 1 && (x - block.getX()) == 0) && !block.isSolid())
                return true;
            return false;
        }

        public bool otherSideOfWall(MapBlock block)
        {
            if ((Math.Abs(x - block.getX()) == 2 && (y - block.getY()) == 0 || Math.Abs(y - block.getY()) == 2 && (x - block.getX()) == 0) && !block.isSolid())
                return true;
            return false;
        }

        public bool intersects(Vector3 point)
        {
            Vector2 pos = new Vector2(point.X, point.Z);
            if (pos.X >= getRealX() - 45 && pos.X <= getRealX() + 45 &&
                pos.Y >= getRealY() - 90 && pos.Y <= getRealY())
                return true;

            return false;
        }

        public int getWidth()
        {
            return width;
        }

        public bool isSolid()
        {
            return solid;
        }

        public void setSolid(bool solid)
        {
            this.solid = solid;
        }

        public int getX()
        {
            return x;
        }

        public int getY()
        {
            return y;
        }

        public int getRealX()
        {
            return x * width;
        }

        public int getRealY()
        {
            return y * width;
        }

        public bool Equals(MapBlock other)
        {
            if (x == other.getX() && y == other.getY())
                return true;
            return false;
        }
    }
}
